package com.demo.Controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zqc
 * @Date 2020/11/12-13:34
 * @Description 控制层
 */
@Api(tags = "swagger测试控制层...")
@RestController
@RequestMapping("/demo")
public class SwaggerTestController {

    @ApiOperation("默认适用所有请求方式，可用method参数指定Get请求方式...")
    @RequestMapping(method = RequestMethod.GET)
    public String helloRequestMethodGet() {
        return "Hello RequestMethod Get";
    }

    @ApiOperation("默认适用所有请求方式，可用method参数指定Post请求方式...")
    @RequestMapping(method = RequestMethod.POST)
    public String helloRequestMethodPost() {
        return "Hello RequestMethod Post";
    }

    @ApiOperation("Get请求，@PathVariable获得请求URL中的动态参数...")
    @GetMapping("/helloGet/{id}")
    public String helloGet(@PathVariable String id) {
        return "Hello Get"+id;
    }

    @ApiOperation("Post请求，@RequestParam将指定的请求参数赋值给方法中的形参...")
    @PostMapping("/helloPost")
    public String helloPost(@RequestParam("password") String password,
                            @RequestParam(value = "loginName",required = false,defaultValue = "admin") String loginName) {
        return "value-name属性的别名，require-指示参数是否绑定，defaultValue-无传参则使用默认值";
    }

    /**
     * 创建接收前端数据的临时实体类，也可写成一个 po 类
     * @Data ：使用lombok-不用写get/set方法等等
     * maven添加依赖：
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
        </dependency>
     *
     * @RequestBody ：能接收到前端数据的关键
     */
    @Data
    private static class LoadingModel{
        @ApiModelProperty("ID")
        private String id;
        @ApiModelProperty("字段1")
        private String firstSegment;
        @ApiModelProperty("字段2")
        private String secondSegment;
    }
    @ApiOperation("循环录入数据...")
    @PostMapping("/updateData")
    public void updateSecondPoolInfo(@RequestBody List<LoadingModel> loadingModels){
        for(LoadingModel loadingModel : loadingModels){
            //遍历对每一个loadingModel进行相关业务操作
        }
    }

}
